package com.android1.amarena2d.test;

import com.android1.amarena2d.actions.base.Action;
import com.android1.amarena2d.actions.interval.RotateBy;
import com.android1.amarena2d.animation.Animation;
import com.android1.amarena2d.animation.Animations;
import com.android1.amarena2d.input.TouchListenerAdapter;
import com.android1.amarena2d.nodes.FpsLabel;
import com.android1.amarena2d.nodes.Scene;
import com.android1.amarena2d.nodes.sprites.SharedSprite;
import com.android1.amarena2d.nodes.SimpleLabel;
import com.badlogic.gdx.graphics.Color;

public class SpriteRotateExampleScene extends Scene {

    SharedSprite sprite;
    Animation animation;

    public SpriteRotateExampleScene() {


        FpsLabel fpsLabel = new FpsLabel(10, 2, Color.WHITE);
        add(fpsLabel);
        add(new SimpleLabel("(Touch the Sprite to start)", 100, 20));

        final Action action = RotateBy.$(1, 360);

        //creating an animation from different images
        animation = Animations.$(1)
                .addFrame("assets/char1.png")
                .addFrame("assets/char2.png").create();

        sprite = new SharedSprite(animation, 100, 100);
        sprite.animation().selectDefault().play();
        sprite.touch().makeTouchable(new TouchListenerAdapter() {
            @Override
            public boolean onTouchDown(float x, float y, int pointer, boolean isHit) {
                sprite.setXY(100, 100);
                sprite.action().stop(action);
                sprite.action().run(action);
                return true;
            }
        });


        add(sprite);


    }


}